/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package oldShit;

import java.sql.*;
import java.util.ArrayList;
import sql.SQLConnector;

/**
 *
 * @author Micke
 */
public class SQLTest {

    private SQLConnector sql;
    private Connection c;
    private Statement st;
    private Statement st2;
    private ResultSet rs;
    private boolean connected;

    public SQLTest() {
        c = null;
        connected = false;

    }

    public boolean Connect() {

        try {
            // get connection to an Oracle database
            c = sql.getConnection();

            st = c.createStatement();
            st2 = c.createStatement();
            connected = true;
            return true;


        } catch (Exception e) {
            // handle the exception
            e.printStackTrace();
            System.exit(1);
        }
        return false;
    }

    public String[] getName() {

        int movieID;
        int yearOfRelease;
        int runtime;
        int budget;
        int[] personID;
        int count = 0;
        String title;
        String language;
        String imgURL;
        String genre;
        String actor[] = new String[20];
        String author;
        String director;
        String producer;

        try {
            ResultSet movieRS = st.executeQuery("SELECT * FROM movie ORDER BY title;");
            //ResultSet actorRS = st2.executeQuery("SELECT persons.firstname,persons.lastname,actor.movieID "
              //      + "FROM actor,persons WHERE persons.personID = actor.personID;");

            while (movieRS.next()) {
                int i = 0;

                movieID = movieRS.getInt("movieID");

                ResultSet actorRS = st2.executeQuery("SELECT persons.firstname,persons.lastname,actor.movieID "
                    + "FROM actor,persons WHERE persons.personID = actor.personID AND actor.movieID="+movieID+";");

                StringBuilder sb = new StringBuilder();

                while (actorRS.next()) {


                    if (actorRS.getInt("movieID") == movieID) {

                        if (i != 0) {
                            sb.append(", ");
                        }
                        sb.append(actorRS.getString("firstName"));
                        //sb.append(" ");
                        sb.append(actorRS.getString("lastName"));
                        i++;
                    }
                }





                actor[count] = sb.toString();
                count++;
            }







        } catch (NullPointerException ne) {
            System.out.println(ne);
            return null;
        } catch (Exception e) {
            System.out.println(e);
            return null;
        }
        
        return actor;
    }
}
